package com.by.interceptor;

import com.by.auto.TokenInterceptionProperties;
import com.by.token.TokenTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 江俊俊
 * @version 1.0
 * @description
 * @date 2025/2/12 19:33
 * @since JDK1.8
 */
public class TokenWebConfig implements WebMvcConfigurer {

    TokenInterceptionProperties properties;

    TokenTemplate tokenTemplate;

    public TokenWebConfig(TokenInterceptionProperties properties, TokenTemplate tokenTemplate) {
        this.properties = properties;
        this.tokenTemplate = tokenTemplate;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new TokenInterception(tokenTemplate))
                .addPathPatterns(properties.getPathPatterns())
                .excludePathPatterns(properties.getExcludePathPatterns());
    }
}
